package com.linux.huhx.main;

import com.linux.huhx.business.service.MyAspectService1;
import com.linux.huhx.business.service.MyAspectService2;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: huhx
 * @Date: 2017-12-15 上午 10:13
 * @Desc: 测试的main类
 */
public class ServiceMain {
    private ApplicationContext context = null;

    @Before
    public void initApplicationContext() {
        context = new ClassPathXmlApplicationContext("application-aop.xml");
    }

    @Test
    public void aspectServiceTest_1() {
        MyAspectService1 myAspectService1 = context.getBean("myService1", MyAspectService1.class);
        myAspectService1.serviceMethod();
    }

    @Test
    public void aspectServiceTest_2() {
        MyAspectService1 myAspectService1 = context.getBean("myService1", MyAspectService1.class);
        myAspectService1.returnServiceMethod();
    }

    @Test
    public void aspectServiceTest_3() {
        MyAspectService1 myAspectService1 = context.getBean("myService1", MyAspectService1.class);
        myAspectService1.throwExceptionMethod();
    }

    @Test
    public void aspectServiceTest_4() {
        MyAspectService1 myAspectService1 = context.getBean("myService1", MyAspectService1.class);
        myAspectService1.aroundServiceMethod1();
    }

    /* 其它的切面实现类 */
    @Test
    public void aspectServiceTest_5() {
        MyAspectService2 myAspectService2 = context.getBean("myService2", MyAspectService2.class);
        Map<String, String> dataMap = new HashMap<>();
        dataMap.put("username", "linux");
        dataMap.put("password", "12345");
        myAspectService2.serviceMethod_1(dataMap);
    }
}
